package com.ms.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: ztd
 * @description:
 */
public class MapperInvokeHandler<T> implements InvocationHandler {
    private Class<T> proxyInterface;

    public MapperInvokeHandler(Class<T> proxyInterface) {
        this.proxyInterface = proxyInterface;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("findUserById")) {
            final User user = new User();
            user.setAge(18);
            user.setId(1);
            user.setName("dada");
            return user;
        }
        return null;
    }

    public T getProxy() {
        return (T)Proxy.newProxyInstance(proxyInterface.getClassLoader(), new Class[]{proxyInterface}, this);
    }
}
